package fun.sboy.panel;

import fun.sboy.listener.MouseCLickListener;
import fun.sboy.pojo.ManagerUser;
import fun.sboy.util.EnterUtil;
import fun.sboy.util.IconUtil;
import fun.sboy.util.JDBCUtil;
import fun.sboy.view.HomeView;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;

public class LoginPanel extends BaseJPanel {


    //第一部分
    private JLabel logoLabel = new JLabel(new ImageIcon(IconUtil.load("logo", 200, 100, 1)));
    //第二部分
    private JPanel inputPanel = new JPanel(null);
    private JLabel usernameLabel = new JLabel(new ImageIcon(IconUtil.load("user", 30, 30, 1)));
    private JLabel passwordLabel = new JLabel(new ImageIcon(IconUtil.load("lock", 30, 30, 1)));

    //共享控件
    public JTextField usernameInput = new JTextField(30);
    public JTextField passwordInput = new JTextField(30);
    public JButton loginBtn = new JButton("Login");
    public JLabel toRegisterLink = new JLabel("没有账号？立即注册");


    public LoginPanel(LayoutManager layout, boolean isDoubleBuffered) {
        super(layout, isDoubleBuffered);
        initialization();
    }

    public LoginPanel(LayoutManager layout) {
        super(layout);
        initialization();
    }

    public LoginPanel(boolean isDoubleBuffered) {
        super(isDoubleBuffered);
        initialization();
    }

    public LoginPanel() {
        initialization();
    }

    @Override
    public void initialization() {
        //设置边框布局
        setLayout(new BorderLayout(0, 10));

        //添加logo布局
        add(logoLabel, BorderLayout.NORTH);

        //数据框等控件
        JLabel[] jLabels = {usernameLabel, passwordLabel};
        JTextField[] jTextFields = {usernameInput, passwordInput};

        int x = 90, y = 10;
        for (JLabel j : jLabels) {
            j.setBounds(x, y, 50, 50);
            inputPanel.add(j);
            y += 50;
        }
        x = 140;
        y = 20;
        Insets insets = new Insets(0, 10, 0, 10);
        for (JTextField j : jTextFields) {
            j.setMargin(insets);
            j.setBounds(x, y, 200, 30);
            inputPanel.add(j);
            y += 50;
        }

        //登录按钮
        loginBtn.setBounds(160, 120, 150, 30);
        loginBtn.setContentAreaFilled(false);
        loginBtn.setDefaultCapable(false);
        inputPanel.add(loginBtn);

        //跳转注册按钮
        toRegisterLink.setBounds(320, 180, 150, 20);
        toRegisterLink.setForeground(new Color(52, 152, 219));
        inputPanel.add(toRegisterLink);

        //将输入框的布局添加到主布局中
        add(inputPanel, BorderLayout.CENTER);
    }

    @Override
    public void reload() {

    }

}
